package com.wslds.blog.action;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.wslds.base.action.BaseAction;
import com.wslds.base.dao.page.PageAdapter;
import com.wslds.bean.Imgtype;
import com.wslds.blog.service.ImgtypeService;

@SuppressWarnings("serial")
@Component("imgtypeAction")
@Scope("prototype")
public class ImgtypeAction extends BaseAction{

	private Imgtype imgtype;
	
	@Resource
	private ImgtypeService imgtypeService;
	
	
	public String listImgtype(){
		return SUCCESS;
	}
	
	public String listAjaxImgtype(){
		PageAdapter<Imgtype> adapter = imgtypeService.getDao().page("imgtype", imgtype, getPage());
		this.put("adapter", adapter);
		return SUCCESS;
	}
	
	
	public String listAllPhoto() throws Exception{
		try{
			List<Imgtype> list = imgtypeService.getDao().find("imgtype", imgtype);
			this.put("list", list);
			
		}catch (Exception e) {
			return ERROR;
		}
		return SUCCESS;
	}
	
	public String insert(){
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
		String loc = "photo" + sdf.format(new Date());
		imgtype.setLoc(loc);
		
		imgtypeService.getDao().save("imgtype", imgtype);
		return SUCCESS;
	}
	
	public String toInsert(){
		List<Imgtype> imgtypeList = imgtypeService.getDao().find("imgtype", null);
		this.put("imgtypeList", imgtypeList);
		return SUCCESS;
	}
	
	public String toUpdate(){
		imgtype = imgtypeService.getDao().findOne("imgtype", imgtype);
		
		List<Imgtype> imgtypeList = imgtypeService.getDao().find("imgtype", null);
		this.put("imgtypeList", imgtypeList);
		
		return SUCCESS;
	}
	
	public String update(){
		imgtypeService.getDao().update("imgtype", imgtype);
		return SUCCESS;
	}

	public Imgtype getImgtype() {
		return imgtype;
	}

	public void setImgtype(Imgtype imgtype) {
		this.imgtype = imgtype;
	}

	public ImgtypeService getImgtypeService() {
		return imgtypeService;
	}

	public void setImgtypeService(ImgtypeService imgtypeService) {
		this.imgtypeService = imgtypeService;
	}



}
